<?php
if (!defined('IN_CONTEXT')) die('access violation error!');

$tpl_names = '';
$tpl_category_names = '';
$category_tmp = array();
$str_tmp = '';

foreach($templates as $v)
{
	$tpl_names .= "'{$v['tpl_name']}',";
}
$tpl_names = substr($tpl_names,0,strlen($tpl_names) -1);


foreach($template_categories as $v)
{
	$tpl_category_names .= "'{$v['tpl_category_name']}',";
}
$tpl_category_names = substr($tpl_category_names,0,strlen($tpl_category_names) -1);
?>
<link rel="stylesheet" type="text/css" href="./script/js/autocomplete/jquery.autocomplete.css" />
<script type="text/javascript" src="./script/js/autocomplete/jquery.autocomplete.js"></script>
<style type="text/css">
table td {
	text-align:left;
}
</style>
<script type="text/javascript" language="javascript">
<!--
$(document).ready(function(){
	var tpl_names = [
		<?php echo $tpl_names;?>
	];
	var tpl_category_names = [
		<?php echo $tpl_category_names;?>
	];
	$("#tpl_name").focus().autocomplete(tpl_names);
	$("#tpl_chinese_name").focus().autocomplete(tpl_category_names);
});

function check_assign_info(thisForm)
{
	$("#stat").css({"display":"block"});
	$("#stat").html("正在保存内容......");
	_ajax_submit(thisForm, on_success, on_failure);
	return false;
}

function on_success(response)
{
	response1 = eval("("+response+")");
	var stat = document.getElementById("stat");
	if(response1.result == 'ok')
	{
		alert(response1.sucmsg);
		stat.innerHTML = "OK，正在重定向......";
		reloadPage();
	}
	else if(response1.result == 'error')
	{
		stat.innerHTML = response1.errmsg;
	}
}

function on_failure(response)
{
	var stat = document.getElementById("stat");
	stat.innerHTML = response;
}
-->
</script>
<div id="stat" style="display:none;"></div>
<form method="post" action="index.php" onsubmit="javascript:return check_assign_info(this);">
<table style='margin-top:20px;' width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#4c4c4c">
<input type="hidden" name="_m" value="<?php echo $next_controller;?>"/>
<input type="hidden" name="_a" value="<?php echo $next_action;?>"/>
<tr>
	<td title="例如:fdc10a1这样的格式">*模板编号</td>
	<td title="例如:fdc10a1这样的格式"><input type="text" name="tpl_name" id="tpl_name"/>&nbsp;<span style='font-size:11px;'>如:fdc10a1(输入时双击显示提示)</span></td>
	<td>*模板行业</td>
	<td>
		<select name="tpl_category_id">
			<?php
			foreach($template_categories as $v)
			{
//				echo "<option value='{$v['tpl_category_id']}'>{$v['tpl_category_name']}</option>";
				if($v['tpl_super_id'] != 0)
				{
					$category_tmp[$v['tpl_super_id']][] = $v; 
				}
			}
			
			foreach($template_categories as $v)
			{
				if(array_key_exists($v['tpl_category_id'],$category_tmp))
				{
					echo "<optgroup label='{$v['tpl_category_name']}'>";
					foreach($category_tmp[$v['tpl_category_id']] as $v1)
					{
						echo "<option value='{$v1['tpl_category_id']}'>{$v1['tpl_category_name']}</option>";
					}
					echo "</optgroup>";
				}
				elseif($v['tpl_super_id'] == 0)
				{
					$str_tmp .= "<option value='{$v['tpl_category_id']}'>{$v['tpl_category_name']}</option>";
				}		
			}
			echo $str_tmp;
			?>
		</select>
	</td>
</tr>
<tr>
	<td title="例如:机械A2">*模板名称</td>
	<td title="例如:机械A2"><input type="text" name="tpl_chinese_name" id="tpl_chinese_name"/>&nbsp;<span style='font-size:11px;'>如:机械A2(输入时双击显示提示)</span></td>
	<td title="建站之星软件版本">*软件版本</td>
	<td>
		<select name="tpl_software_version">
		<?php 
		foreach($sitestar_versions as $v)
		{
			if($v['sf_current_version'] == 'Y')
			{
				echo "<option SELECTED='SELECTED' value='{$v['sf_version']}'>{$v['sf_version']}</option>";
			}
			else
			{
				echo "<option value='{$v['sf_version']}'>{$v['sf_version']}</option>";
			}
		}
		?>
		</select>
	</td>
</tr>
<tr>
	<td>*模板制作类型</td>
	<td>
		<select name="tpl_type">
			<option value="1">提供设计[外包B1]</option>
			<option value="2">完全设计[外包B2]</option>
			<option value="3" SELECTED='SELECTED'>完全设计[内部B3]</option>
		</select>
	</td>
	<td>*设计人员</td>
	<td>
		<?php 
		if($allow_assignTplFlag != 1)
		{
		?>
		<select name="tpl_designer_id">
		<?php 
		foreach($designers as $v)
		{
			echo "<option value='{$v['u_id']}'>{$v['u_name']}</option>";
		}
		?>
		</select>
		<?php 
		}
		else
		{
			echo "<select name='tpl_designer_id'><option value='$u_id1'>$u_name1</option></select>";
		}
		?>
	</td>
</tr>
<tr>
<td>设计目标</td>
<td colspan="3"><textarea cols="60" rows="20" name="tpl_master_assign_comment" id="tpl_master_assign_comment"></textarea></td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="派发"/>
<input type="reset" value="重置"/>
</td>
</tr>
</table>
</form>
